package qidi.gushi;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.iflytek.voicedemo.R;

import java.util.ArrayList;
/**
 韩梦飞沙 韩亚飞 313134555@qq.com yue31313 han_meng_fei_sha
 on 2018/2/4.
 古诗网格适配器
 */
public class GuShiAdapter extends BaseAdapter
{
    /**
     How many items are in the data set represented by this Adapter.

     @return Count of items.
     */
    @Override
    public int getCount()
    {
        return list.size();
    }
    /**
     Get the data item associated with the specified position in the data set.

     @param position Position of the item whose data we want within the adapter's
     data set.

     @return The data at the specified position.
     */
    @Override
    public Object getItem(int position)
    {
        return list.get(position);
    }
    /**
     Get the row id associated with the specified position in the list.

     @param position The position of the item within the adapter's data set whose row id we want.

     @return The id of the item at the specified position.
     */
    @Override
    public long getItemId(int position)
    {
        return 0;
    }
    /**
     Get a View that displays the data at the specified position in the data set. You can either
     create a View manually or inflate it from an XML layout file. When the View is inflated, the
     parent View (GridView, ListView...) will apply default layout parameters unless you use
     {@link LayoutInflater#inflate(int,ViewGroup,boolean)}
     to specify a root view and to prevent attachment to the root.

     @param position    The position of the item within the adapter's data set of the item whose view
     we want.
     @param convertView The old view to reuse, if possible. Note: You should check that this view
     is non-null and of an appropriate type before using. If it is not possible to convert
     this view to display the correct data, this method can create a new view.
     Heterogeneous lists can specify their number of view types, so that this View is
     always of the right type (see {@link #getViewTypeCount()} and
     {@link #getItemViewType(int)}).
     @param parent      The parent that this view will eventually be attached to

     @return A View corresponding to the data at the specified position.
     */
    @Override
    public View getView(int position,View convertView,ViewGroup parent)
    {
        /*if(list==null||list.size()==0){
            return convertView;
        }
        ViewHolder viewHolder;
        if (convertView == null) {
            viewHolder = new ViewHolder();
            convertView = LayoutInflater.from(context).inflate(R.layout.layout_gushi, parent, false);
            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }
        viewHolder.zi = (TextView) convertView.findViewById(R.id.zi);
        viewHolder.zi.setText(list.get(position));*/
        convertView = LayoutInflater.from(context).inflate(R.layout.layout_gushi, parent, false);
        TextView zi = (TextView) convertView.findViewById(R.id.zi);
        zi.setText(list.get(position));
        return convertView;
    }
    /**构造*/
    public GuShiAdapter(Context context)
    {
        this.context=context;
        String gushi = "众鸟高飞尽，孤云独去闲。相看两不厌，只有敬亭山。";
        for(int i=0;i<gushi.length();i++){
            list.add(gushi.charAt(i)+"");
        }
    }
    /**存放古诗，一个字一个位置。*/
    static ArrayList<String> list = new ArrayList<String>();
    /**环境*/
    Context context;
    /**用优化网格控件的类*/
    static class ViewHolder {
        /**古诗的一个字*/
        TextView zi;
    }
    public static ArrayList<String> getList()
    {
        return list;
    }
}
